package cn.ailanyin.home.config;

import cn.ailanyin.home.constant.BaseConstant;
import cn.hutool.core.util.URLUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 本地文件上传配置-集群环境勿用
 *
 * @author ailanyin
 * @date 2023-09-27 09:00:52
 */
@Configuration
public class LocalFileConfig implements WebMvcConfigurer {

    @Value("${file.uploadPath}")
    private String uploadPath;

    /**
     * 配置静态文件资源服务器
     *
     * @param registry registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(BaseConstant.RESOURCE_PATTERN)
                .addResourceLocations(URLUtil.FILE_URL_PREFIX + uploadPath);

    }

}
